package com.yb.guigu.pick.security.generator;

import com.yb.guigu.pick.security.bean.GuiguPickUserRequest;
import com.yb.guigu.pick.security.bean.GuiguUsernamePasswordAuthenticationToken;
import com.yb.guigu.pick.security.bean.GuiguPickUser;
import com.yb.guigu.pick.core.constant.LoginTypeEnum;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/5/31 18:35
 * FileName: UsernamePasswordAuthenticationTokenGenerator
 * Description:
 */

@Component
public class UsernamePasswordAuthenticationTokenGenerator implements AuthenticationTokenGenerator{
    @Override
    public Authentication unauthenticated(GuiguPickUserRequest userRequest) {

        return GuiguUsernamePasswordAuthenticationToken.unAuthenticated(new GuiguPickUser(userRequest));
    }

    @Override
    public boolean support(GuiguPickUserRequest userRequest) {
        return LoginTypeEnum.USER_PASS.getLoginType().equalsIgnoreCase(userRequest.getLoginType());
    }

    @Override
    public boolean support(GuiguPickUser guiguPickUser) {
        return  LoginTypeEnum.USER_PASS.getLoginType().equalsIgnoreCase(guiguPickUser.getLoginType());
    }

    @Override
    public Authentication authenticated(GuiguPickUser guiguPickUser) {
        return GuiguUsernamePasswordAuthenticationToken.authenticated(guiguPickUser,guiguPickUser.getAuthorities());
    }
}
